﻿@{
    ViewBag.Title = "InsAccount";
}
@section scripts
{   
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>       
    <script src="@Url.Content("~/Scripts/common/gridlayout.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/common/export.js")" type="text/javascript"></script>
}
<div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <a class="mini-button" id="refresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                <span class="separator"></span>
                <a class="mini-button" id="del" name="del" iconCls="icon-remove" onclick="delBill" plain="true">删单</a>
                <span class="separator"></span>
                <a class="mini-button" id="export" iconCls="icon-node" onclick="setExportExcel('datagrid1')"plain="true">导出</a>
                <span class="separator"></span>
                <a class="mini-button" id="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
            </td>
        </tr>
    </table>                
</div>
<form id="form1">
    <div id = "DivHeader" style="margin-left:0px;margin-top:0px;">
        <table style="margin-bottom:4px;">
            <tr>
                <td width ="80px" align="right">单据日期：</td>
                <td width ="200px">
                    @Html.Partial("~/Views/Modular/dxDateRange.cshtml") 
                </td>
                <td width="80px" height ="32px" align="right">门店名称：</td>
                <td width="200px" height ="32px">
                    @Html.Partial("~/Views/Modular/LookupStockInfo.cshtml")
                </td>
                <td width ="70px" align="right">付款项目：</td>
                <td width ="80px">
                        @Html.Partial("~/Views/Modular/LookupPayItem.cshtml")
                </td>
            </tr>
            <tr>
                <td width ="80px" align="right">单据编号：</td>
                <td width ="307px">
                    &nbsp;<input name="FBillNo" class="mini-textbox" style="width:307px;"/>
                </td>
                <td width ="80px" align="right">供应商名：</td>
                <td width ="200px">    
                    @Html.Partial("~/Views/Modular/LookupSupply.cshtml")
                </td>
                <td width ="70px" align="right">状态：</td>
                <td width ="80px">
                    <input id="comStatus" name="comStatus" class="mini-combobox" style="width:80px;" textField="text" valueField="id" 
                               data="fstatus" value="-100"  allowInput="true" showNullItem="true" nullItemText="请选择..." tabindex="3"/>
                </td>
            </tr>
        </table>
    </div>
</form>
        <div class="mini-fit" >
            <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                    borderStyle="border:1;" url="InsAccList"   showSummaryRow="true"
                    allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"   ondrawsummarycell="onDrawSummaryCell"
                    onrowdblclick="modify"  sortMode="client" >
                <div property="columns">
                    <div type="checkcolumn" >选行</div>
                    <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                    <div field="FDate" name="FDate" width="80" headeralign="center" allowsort="true" dateFormat="yyyy-MM-dd">日期</div>
                    <div field="FBillNo" name="FBillNo" width="150" headeralign="center" allowsort="true">单据编号</div>
                    <div field="FExplanation" name="FExplanation" width="150" headeralign="center" allowsort="true">摘要</div>
                    <div field="FStockName" name="FStockName" width="100" headeralign="center" allowsort="true">门店名称</div>
                    <div field="FSupplyName" name="FSupplyName" width="120" headeralign="center" allowsort="true">供应商名</div>
                    <div field="FPayAmount" name="FPayAmount" width="80" headeralign="center" align="right" allowsort="true" numberFormat="#,0.00">付款金额</div>
                    <div field="FState" name="FState" width="60" headeralign="center" allowsort="true">状态</div>
                    <div field="FPayItemName" name="FPayItemName" width="100" headeralign="center" allowsort="true">付款项目</div>
                    <div field="FCheckDate" name="FCheckDate" width="100" headeralign="center" allowsort="true" dateFormat="yyyy-MM-dd">审核日期</div>
                    <div field="FCheckerName" name="FCheckerName" width="80" headeralign="center" allowsort="true">审核人</div>
                </div>
            </div>
        </div>

<input type="hidden" id="type" value="@ViewBag.type" />

<script>
    var fstatus = [{ "id": "-100", "text": "全部" },
                    { "id": "0", "text": "未审核" },
                    { "id": "1", "text": "已审核" }]
    var sumFields = "FPayAmount";
    mini.parse();
    var grid = mini.get("datagrid1");
    //通用shown自动调用些方式
    function FormShown() {
        var toDay = new Date();
        mini.getbyName("FDate1").setValue(toDay);
        mini.getbyName("FDate2").setValue(toDay);
    }

    $(function () {
        LoadListData();
    });

    //加载资料列表
    function LoadListData() {
        var form = new mini.Form("#form1");
        var data = form.getData(true, false);
        var formjson = mini.encode(data);
        var sSystemAppID = parent.window.getSystemAppID();
        var json = "[{";
        json = json + "'FSystemAppID':" + "'" + sSystemAppID + "',";
        json = json + "'search':'" + formjson + "','type':'" + $("#type").val() + "'}]";
        var grid = mini.get("datagrid1");
        grid.load({ mydata: json });

        mExportDataUrl = grid.url;
        mExportDataJson = json;

    }

    //搜索资料列表
    function search() {
        LoadListData();
    }

    ///增加资料
    function newBill() {
        var uID = parent.window.getSystemAppID();
        mini.open({
            url: "/Account/InsPayInfo?type=" + $("#type").val(),
            title: '进货付款', width: 680, height: 350,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", FItemID: "0" };
                debugger;
                iframe.contentWindow.SetInfoData(data);
            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    }

    //修改资料
    function modify() {
        var row = grid.getSelected();
        if (row) {
            parent.window.showTabByIdEx(205,'InsDataPay', '进货付款单', '../Account/InsDataPay?datatype=17&billid=' + row.FItemID);
        }
    }

    function printdata() {
        var url = "../Report/PrintReport";
        mini.open({
            url: url,
            title: "打印", width: 1000, height: 700,
            onload: function () {
                var iframe = this.getIFrameEl();
                var NoneDisplayCol = [0];
                iframe.contentWindow.InitalPrint(grid, NoneDisplayCol, "付款明细表");
            }
        });
    }


    function delBill() {
        var row = grid.getSelected();
        if (!row) { mini.alert("请选中一行再操作?"); return; }
        if (row.FCheckFlag == 1) {
            mini.alert("此单已审核，不能删除!");
            return;
        }
        mini.confirm("确定要删除选中行吗？", "提示",
            function (action) {
                if (action == "ok") {
                    remove();
                }
            });
    }
    function remove() {
        var row = grid.getSelected();
        if (row) {
            var json = '[{"FSystemAppID":"' + parent.window.getSystemAppID()
                + '","FItemID":"' + row.FItemID
                + '","type":' + $("#type").val() + '}]';
            $.post("DelAccount", { mjson: json }, function (data) {
                var ret = mini.decode(data);
                if (ret.status == 1) {
                    mini.showMessageBox({
                        showModal: false, width: 250, title: "提示", iconCls: "mini-messagebox-info",
                        message: ret.msg, timeout: 3000, x: "right", y: "bottom"
                    });
                    grid.reload();
                }
                else {
                    mini.alert("错误:" + ret.error);
                }
                mini.get("datagrid1").reload();
            });
        }
    }
</script>